#include "../include/ClassStack.h"
#include <iostream>
using namespace std;
using namespace  classStack;
Stack::Link::Link(void *dat, Link *nxt)
{
    data = dat;
    next = nxt;
}
Stack::Link::~Link()
{
}

Stack::Stack()
{
    head = 0;
}

void Stack::push(void *dat)
{
    Link *newLink = new Link(dat, head);
    head = newLink;
}

void* Stack::peek()
{
    return head->data;
}

void* Stack::pop()
{
    if (head == 0)
    {
        return 0;
    }
    void *result = head->data;
    Link *oldHead = head;
    head = head->next;
    delete oldHead;
    return result;
}

Stack::~Stack()
{
    while (head != 0 && head->next != nullptr)
    {
        pop();
    }
    cout << "cleanup over" << endl;
}